
Use it to control things you want to vary over a range of values, such as the speed of a motor, the intensity of a light and much more!
Use a GVS cable to connect the sensor. This has 3 wires, blue, red and black:
Wire up as follows, using the Edge Connector or Motor Controller board:
Potentiometer | Microbit |
---|---|
3-pin connector | P0 3-pin connector |
You don't have to use pin P0. You can use any analogue pin. Just remember to adjust your code accordingly.
Enter this code in forever:
The Serial blocks can be found in Advanced.
Download the code to the microbit.
To see the data, click on Show data Device:
You should see some numbers and a graph. These show the position of the potentiometer knob. Rotate the knob and watch the values change:
You can use these values to control other things. For example, in the code below, we can use this to control the bar graph function of the Microbit:
In the above code, the map block takes the potentiometer value, which is in the range 0 to 1023, and uses it to plot a bar chart on the LED display: